package com.example.device.maintain

import androidx.activity.viewModels
import com.alibaba.android.arouter.facade.annotation.Route
import com.blankj.utilcode.util.ToastUtils
import com.example.common.view.view.BaseMvvmActivity
import com.example.device.R
import com.example.device.databinding.ActivityMaintainAddBinding
import com.example.device.entity.MaintainEntity
import com.example.device.vm.MaintainAddViewModel
import dagger.hilt.android.AndroidEntryPoint
import java.text.SimpleDateFormat
import java.util.Locale

@Route(path = "/device/MaintainAddActivity")
@AndroidEntryPoint
class MaintainAddActivity : BaseMvvmActivity<ActivityMaintainAddBinding>() {
    override fun getLayoutId(): Int = R.layout.activity_maintain_add
    private val maintainAddViewModel : MaintainAddViewModel by viewModels()

    override fun initView() {
        super.initView()
        mDataBinding.back.setOnClickListener {
            finish()
        }
        mDataBinding.submitBtn.setOnClickListener {
            // 获取当前时间
            val currentTime = SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()).format(System.currentTimeMillis())

            val maintainEntity = MaintainEntity(
                contactMethod= mDataBinding.contactMethod.text.toString() ,
                faultDescription= mDataBinding.faultDescription.text.toString()  ,
                faultPhotos=  "http://example.com/photo1.jpg,http://example.com/photo2.jpg",
                id=  0,
                orderNumber=  "WX${mDataBinding.contactMethod.text}" ,
                processingStatus=  "待处理",
                repairLocation= mDataBinding.repairLocation.text.toString() ,
                repairName= mDataBinding.repairName.text.toString(),
                repairTime=  currentTime,
                userId=  8 ,
            )
            maintainAddViewModel.postMaintain(maintainEntity)
        }
        maintainAddViewModel.mSuccessLiveData.observe(this){
            ToastUtils.showLong("提交成功")
            finish()
        }
        maintainAddViewModel.mErrorLiveData.observe(this){
               ToastUtils.showLong(it)
        }

    }
}